﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace supermarket.method
{
    public static class CommonHelper
    {
        public static string GetMD5Str(string str)
        {
            using (MD5 md5 = MD5.Create())
            {
                // 将输入字符串转换为字节数组
                byte[] inputBytes = Encoding.UTF8.GetBytes(str);
                // 计算输入字节数组的哈希值
                byte[] hashBytes = md5.ComputeHash(inputBytes);
                // 将字节数组转换为字符串
                StringBuilder hashString = new StringBuilder();
                foreach (byte b in hashBytes)
                {
                    hashString.AppendFormat("{0:x2}", b);
                }
                return hashString.ToString().ToUpper();
            }
        }

        public static bool IsValidPhoneNumber(string phoneNumber)
        {
            // 定义手机号的正则表达式
            string pattern = @"^1[3456789]\d{9}$";

            // 使用Regex.IsMatch方法进行匹配
            return Regex.IsMatch(phoneNumber, pattern);
        }

    }
}
